<!--

    Copyright © 2016-2025 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="tb-widget-button-custom-style-panel" [formGroup]="customStyleFormGroup">
  <div class="tb-widget-button-custom-style-title">{{ widgetButtonStateTranslationMap.get(state) | translate }}</div>
  <div class="tb-widget-button-custom-style-panel-content">
    <div class="tb-form-row space-between">
      <mat-slide-toggle class="mat-slide" formControlName="overrideMainColor">
        {{ 'widgets.button.main' | translate }}
      </mat-slide-toggle>
      <tb-color-input asBoxInput
                      formControlName="mainColor">
      </tb-color-input>
    </div>
    <div class="tb-form-row space-between">
      <mat-slide-toggle class="mat-slide" formControlName="overrideBackgroundColor">
        {{ 'widgets.button.background' | translate }}
      </mat-slide-toggle>
      <tb-color-input asBoxInput
                      formControlName="backgroundColor">
      </tb-color-input>
    </div>
    <div class="tb-form-row space-between column-xs">
      <mat-slide-toggle class="mat-slide" formControlName="overrideDropShadow">
        {{ 'widgets.button.shadow' | translate }}
      </mat-slide-toggle>
      <mat-chip-listbox formControlName="dropShadow">
        <mat-chip-option [selectable]="!customStyleFormGroup.get('dropShadow').value" [value]="true">{{ 'widgets.button.enabled' | translate }}</mat-chip-option>
        <mat-chip-option [selectable]="customStyleFormGroup.get('dropShadow').value" [value]="false">{{ 'widgets.button.disabled' | translate }}</mat-chip-option>
      </mat-chip-listbox>
    </div>
    <div class="tb-widget-button-custom-style-preview">
      <div class="tb-widget-button-custom-style-preview-title" translate>
        widgets.button.preview
      </div>
      <tb-widget-button
        #widgetButtonPreview
        [appearance]="previewAppearance"
        [borderRadius]="borderRadius"
        [autoScale]="autoScale"
        disableEvents
        [hovered]="state === widgetButtonState.hovered"
        [pressed]="state === widgetButtonState.pressed"
        [activated]="state === widgetButtonState.activated"
        [disabled]="state === widgetButtonState.disabled">
      </tb-widget-button>
    </div>
  </div>
  <div class="tb-widget-button-custom-style-panel-buttons">
    <button *ngIf="copyFromStates?.length"
            #copyStyleButton
            class="tb-nowrap"
            mat-stroked-button
            color="primary"
            type="button"
            [matMenuTriggerFor]="styleSourcesMenu" [matMenuTriggerData]="{menuWidth: copyStyleButton._elementRef.nativeElement.clientWidth}">
      {{ 'widgets.button.copy-style-from' | translate }}
    </button>
    <mat-menu #styleSourcesMenu="matMenu">
      <ng-template matMenuContent let-menuWidth="menuWidth">
        <div [style.min-width.px]="menuWidth">
          <button mat-menu-item *ngFor="let state of copyFromStates" (click)="copyStyle(state)">{{ widgetButtonStateTranslationMap.get(state) | translate }}</button>
        </div>
      </ng-template>
    </mat-menu>
    <span class="flex-1"></span>
    <button mat-button
            color="primary"
            type="button"
            (click)="cancel()">
      {{ 'action.cancel' | translate }}
    </button>
    <button mat-raised-button
            color="primary"
            type="button"
            (click)="applyCustomStyle()"
            [disabled]="customStyleFormGroup.invalid || !customStyleFormGroup.dirty">
      {{ 'action.apply' | translate }}
    </button>
  </div>
</div>
